package com.stone.aop;

/**
 * 增强类
 */

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class UserProxy {

    // 相同切入点抽取
    @Pointcut(value = "execution(* com.stone.aop.User.add(..))")
    public void pointdemo(){
    }

    // @Before 注解表示作为前置通知
    @Before(value = "pointdemo()")
    public void before() {
        System.err.println("before............");
    }

    @After(value = "execution(* com.stone.aop.User.add(..))")
    public void after() {
        System.err.println("after .... ");
    }

    @AfterThrowing(value = "execution(* com.stone.aop.User.add(..))")
    public void afterThrowing() {
        System.err.println("afterThrowing .... ");
    }

    @AfterReturning(value = "execution(* com.stone.aop.User.add(..))")
    public void afterReturning() {
        System.err.println("afterReturning .... ");
    }

    // 环绕通知
    @Around(value = "execution(* com.stone.aop.User.add(..))")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.err.println("around ....  之前");
        // 被增强的方法执行
        proceedingJoinPoint.proceed();
        System.err.println("around ....  之后");
    }
}
